<template>
	<view class='sidebar'>
		<view class="pageHead dFlex jAround_aCenter" :style="{'padding-top':header_top+'px'}">
			<u-icon name="list-dot" @click='infoDialog = true' color='#ffffff' size='24px'></u-icon>
			<u-search :placeholder="$t('search.placeholder1')" :showAction='false' style="margin: 0 12px;"></u-search>
			<u-icon name="home" @click='goTab("/pages/home")' color='#ffffff' size='26px'
				style="margin-right: 6px;"></u-icon>
			<u-icon name="../static/menu4_1.png" @click='goTab("/pages/account")' color='#ffffff' size='20px'></u-icon>
		</view>
		<!-- 弹出层 -->
		<u-popup :show="infoDialog" mode="left" @open='getInfo' @close='infoDialog = false' :closeOnClickOverlay='true'>
			<view class='content'>
				<view class='userInfo' v-if="token" @click='goTab("./account")'>
					<text>{{userInfo.username}}! </text>
					<view class="showAccount">{{$t('account.welcome_title1')}}</view>
				</view>
				<view class='menus'>
					<view class="partLine dFlex jBetween_aCenter" @click='goPage("./profile")'>
						<view class="line_content dFlex jStart_aCenter">
							<view class="line_icon imgPublic">
								<image src="../static/images/gerenxinxi.png" mode="widthFix"></image>
							</view>
							<text>{{$t('account.my_info')}}</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="partLine dFlex jBetween_aCenter" @click='goPage("./address")'>
						<view class="line_content dFlex jStart_aCenter">
							<view class="line_icon imgPublic">
								<image src="../static/images/address.png" mode="widthFix"></image>
							</view>
							<text>{{$t('account.address')}}</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="partLine dFlex jBetween_aCenter" @click='goPage("./feedback")'>
						<view class="line_content dFlex jStart_aCenter">
							<view class="line_icon imgPublic">
								<image src="../static/images/yijian.png" mode="widthFix"></image>
							</view>
							<text>{{$t('account.feedback')}}</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="partLine dFlex jBetween_aCenter" @click='goPage("./coupon")'>
						<view class="line_content dFlex jStart_aCenter">
							<view class="line_icon imgPublic">
								<image src="../static/images/youhui.png" mode="widthFix"></image>
							</view>
							<text>{{$t('account.coupon')}}</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="partLine dFlex jBetween_aCenter" @click='goXieyi(1)'>
						<view class="line_content dFlex jStart_aCenter">
							<view class="line_icon imgPublic">
								<image src="../static/images/xieyi.png" mode="widthFix"></image>
							</view>
							<text>{{$t('login.xieyi2')}}</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="partLine dFlex jBetween_aCenter" @click='goXieyi(2)'>
						<view class="line_content dFlex jStart_aCenter">
							<view class="line_icon imgPublic">
								<image src="../static/images/yinsi.png" mode="widthFix"></image>
							</view>
							<text>{{$t('login.xieyi4')}}</text>
						</view>
						<u-icon name="arrow-right"></u-icon>
					</view>
					<view class="partLine dFlex jBetween_aCenter" @click='goXieyi(2)'>
						<view class="line_content dFlex jStart_aCenter">
							<view class="line_icon imgPublic">
								<image src="../static/images/tuichu.png" mode="widthFix"></image>
							</view>
							<text>{{$t('account.quit')}}</text>
						</view>
					</view>
					
				</view>
				 
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		name: "sidebar",
		data() {
			return {
				token: '',
				userInfo: {},
				header_top: getApp().globalData.header_top,
				header_height: getApp().globalData.header_height,
				infoDialog: false,
				// 切换语言
				language: ["English", "بالعربية","简体中文"],
				langIdx: 0,
			};
		},
		mounted() {
			this.token = this.$cache.get('token')
			this.userInfo = this.$cache.get('userInfo')
		},
		methods: {
			// 窗口打开时获取用户信息
			loginOut() {
				const _this = this;
				uni.showModal({
					title: this.$t('account.tips_title1'),
					content: this.$t('account.tips_content1'),
					cancelText: this.$t("operateBtn.cancelBtn"),
					confirmText: this.$t("operateBtn.sureBtn"),
					success(res) {
						if (res.confirm) {
							_this.$cache.set('token', null)
							_this.$cache.set('userInfo', null)
							_this.token = ''
							_this.userInfo = ''
						}
					}
				})
			},
			getInfo() {

			},
			goXieyi(type) {
				uni.navigateTo({
					url: './xieyi?type=' + type
				})
			},
			goPage(url) {
				if (!this.token) {
					this.loginDialog = true
				} else {
					uni.navigateTo({
						url: url
					})
				}
			},
			goTab(url) {
				uni.switchTab({
					url: url,
				})
			},
			// 选择语言
			chooseLanguage(e) {
				this.langIdx = e.detail.value;
				var arr = [ 'en', 'sa','zh'];
				this.$i18n.locale = arr[this.langIdx];
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		.partContent {
			.partLine {
				.line_content {
					.line_icon {
						width: 24px;
						height: 24px;
						margin-right: 8px;
					}

					width: max-content;
					color: #404553;
				}

				font-size: 12px;
				width: 100%;
				padding:10px 12px;
				box-sizing: border-box;
			}

			width: 100%;
		}

		.menus {
			border-bottom: 12px solid #f8f8f8;

			.partLine {
				.line_content {
					.line_icon {
						width: 20px;
						height: 20px;
						margin-right: 8px;
					}

					width: max-content;
					font-size: 13px;
					color: #404553;
				}

				width: 100%;
				padding:8px;
				box-sizing: border-box;
			}
		}

		.userInfo {
			.showAccount {
				width: 100%;
				margin-top: 5px;
				font-size: 12px;
				color: #999999;
				font-weight: normal;
			}

			width: 100%;
			padding: 8px;
			height: max-content;
			box-sizing: border-box;
			background: white;
			font-weight: bold;
			border-bottom: 12px solid #f8f8f8;
		}

		/* width: 40vw; */
		height: 100%;
	}

	.pageHead {
		background: $main;
	}
</style>